/*
 * @Author: boyyang
 * @Date: 2022-01-01 23:23:55
 * @LastEditTime: 2022-02-20 11:30:45
 * @LastEditors: boyyang
 * @Description: vite.config.ts 配置文件
 * @FilePath: \boyyang\vite.config.ts
 */

import { ConfigEnv, defineConfig, UserConfig, loadEnv } from 'vite'
import { visualizer } from 'rollup-plugin-visualizer'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
const path = require('path')

// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
  const root = process.cwd()
  const env = loadEnv(mode, root)
  return {
    base: './',
    resolve: {
      alias: {
        "@": "/src"
      }
    },
    plugins: [
      vue(),
      AutoImport({
        imports: ['vue', 'vue-router'],
        // 可以选择auto-import.d.ts生成的位置，使用ts建议设置为'src/auto-import.d.ts'
        dts: 'src/auto-import.d.ts'
      }),
      Components({
        dirs: ['src/components'],
        extensions: ['vue'],
        // 配置文件生成位置
        dts: 'src/components.d.ts'
      }),
      visualizer()
    ],
    server: {
      host: '0.0.0.0',
      port: 3000,
      proxy: {
        '/api': {
          target: 'https://autumnfish.cn',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, '')
        }
      },
      cors: true
    },
    build: {
      assetsDir: 'assets',

      // target: "es2019",
      // brotliSize: false,
      // chunkSizeWarningLimit: 2000,
      // lib: {
      //   entry: path.resolve(__dirname, 'plugin/index.ts'),
      //   name: 'boyyangUi',
      //   fileName: (format) => `my-lib.${format}.js`
      // },
      // rollupOptions: {
      //   // 确保外部化处理那些你不想打包进库的依赖
      //   external: ['vue'],
      //   output: {
      //     // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
      //     globals: {
      //       vue: 'Vue'
      //     }
      //   }
      // }
    }
  }
})

